package com.deeper.customview.ui.c1.demo;

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.deeper.customview.BaseFragment;
import com.deeper.customview.R;

public class Chapter01Demo04Fragment extends BaseFragment {
    private ImageView iv;


    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View root = inflater.inflate(R.layout.fragment_chapter01_demo04, container, false);

        iv = root.findViewById(R.id.iv);

        Bitmap bmpBuffer = Bitmap.createBitmap(500, 800, Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(bmpBuffer);

        float startX = 20;
        float startY = 30;
        float stopX = 100;
        float stopY = 150;
        Paint paint = new Paint();
        paint.setAntiAlias(true);
        paint.setStrokeWidth(5);
        paint.setColor(Color.RED);
        canvas.drawLine(startX, startY, stopX, stopY, paint);

        final int offsetDy = 50;
        for (int i = 1; i < 6; i++) {
            canvas.drawLine(50, offsetDy * i, 300, offsetDy * i, paint);
        }

        iv.setImageBitmap(bmpBuffer);
        return root;
    }
}
